// pages/personal/personal.js
const app = getApp()
var utils = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
	onShow: function (options) {
        this.personalInfo();
		this.systemInfo();
    },
    //用户信息
    personalInfo: function (keyword) {
        var that = this;
        utils.http("/api/v1/member/index", {
        }, function (res) {
            if (res.state == 1) {
                that.setData({
                    info: res.datas
                })
            } else {
                utils.message(res.datas)
            }
        })
    },
	//获取站点配置信息 
	systemInfo: function () {
		var that = this;
		utils.http("/api/v1/common/system", {}, function (res) {
			if (res.state == 1) {
				that.setData({
					system: res.datas
				})
			} else {
				utils.message(res.datas)
			}
		})
	},
	//主管登录
	onAdministratorsTap:function(e){
		console.log(wx.getStorageSync("openid").openid == undefined,"klsdjfkldsjfk")
		if (wx.getStorageSync("openid").openid ==undefined){
			wx.navigateTo({
				url: "../dministratorsLogin/dministratorsLogin",
			})	
		}else{
			wx.navigateTo({
				url: "../dministratorsIndex/dministratorsIndex",
			})
			
		}
		
	},
	//进入店铺
	onStoreTap() {
		wx.navigateToMiniProgram({
			appId: 'wxce2b481e0e1c4ba8',
			path: 'pages/index/index',
			extraData: {
				foo: 'bar'
			},
			envVersion: 'trial',
			success(res) {
				// 打开成功
			}
		})
	},
	//进入骑手
	onRiderTap(){
		wx.navigateToMiniProgram({
			appId: 'wx8591b5ca048834c8',
			path: 'pages/index/index',
			extraData: {
				foo: 'bar'
			},
			envVersion: 'trial',
			success(res) {
				// 打开成功
			}
		})
	},
    //跳入我的地址
    onAddressTap:function(res){
        wx.navigateTo({
            url: '../address/address',
        })
    },
    //我的评价
    onEvaluatetap:function(res){
        wx.navigateTo({
            url: '../evaluate/evaluate',
        })
    },
    //跳入推广二维码
    onCodeTap:function(res){
        wx.navigateTo({
            url: '../code/code',
        })
    },
    //我的推荐
    distriButiontap:function(res){
        wx.navigateTo({
            url: '../distribution/distribution',
        })
    },
    //邀请用户
    onInviteUsersTap(){
        wx.navigateTo({
            url: '../inviteUsers/inviteUsers'
        })
    },
    //客服电话
    onPhoneTap: function (e) {
        var that = this;
		console.log(that.data.system)
        wx.makePhoneCall({
			phoneNumber: that.data.system.kefu_phone //仅为示例，并非真实的电话号码
        })
    },

	//授权登陆
	bindGetUserInfo: function (e) {
		var that = this;
		 console.log(e)
		if (e.detail.errMsg == "getUserInfo:ok") {
			var data = {
				nickname: e.detail.userInfo.nickName,
				sex: e.detail.userInfo.gender,
				avatar: e.detail.userInfo.avatarUrl
			}
			console.log(data)
			// app.memberModify(data);
			utils.http("/api/v1/member/member_modify",data, function (res) {
				if (res.state == 1) {
					that.setData({
						info: res.datas
					})
					that.personalInfo();
				} else {
					utils.message(res.datas)
				}
			})
			

		}
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})